﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【库存信息】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto库存信息
    /// </summary>
    public abstract class AutoStockMapping : BaseMapping<Stock, StockModel, StockFilterModel>
    {
        public AutoStockMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override StockModel Entity2Model(Stock entity)
        {
            StockModel model = new StockModel();

            model.StockID = entity.StockID;
            model.GroupInfoID = entity.GroupInfoID;
            model.BillID = entity.BillID;
            model.BillDetailID = entity.BillDetailID;
            model.WarehouseID = entity.WarehouseID;
            model.WarehouseName = entity.WarehouseName;
            model.WarehousePositionID = entity.WarehousePositionID;
            model.WarehousePositionName = entity.WarehousePositionName;
            model.Code = entity.Code;
            model.GuiGe = entity.GuiGe;
            model.Diameter = entity.Diameter;
            model.Cnt = entity.Cnt;
            model.Name = entity.Name;
            model.NianJu = entity.NianJu;
            model.MpaID = entity.MpaID;
            model.MpaName = entity.MpaName;
            model.SurfaceStatusID = entity.SurfaceStatusID;
            model.SurfaceStatusName = entity.SurfaceStatusName;
            model.TwistingTypeID = entity.TwistingTypeID;
            model.TwistingTypeName = entity.TwistingTypeName;
            model.LengthNum = entity.LengthNum;
            model.KeepDay = entity.KeepDay;
            model.SupplierID = entity.SupplierID;
            model.SupplierName = entity.SupplierName;
            model.ProducerID = entity.ProducerID;
            model.ProducerName = entity.ProducerName;
            model.ChuChang_FilesList = entity.ChuChang_Files.GetFileList();
            model.YanShou_FilesList = entity.YanShou_Files.GetFileList();
            model.JianCe_FilesList = entity.JianCe_Files.GetFileList();
            model.Attr_FilesList = entity.Attr_Files.GetFileList();
            model.DepartmentID = entity.DepartmentID;
            model.HoisterID = entity.HoisterID;
            model.HoisterName = entity.HoisterName;
            model.HoisterUsageID = entity.HoisterUsageID;
            model.HoisterUsageName = entity.HoisterUsageName;
            model.WireropeTypeID = entity.WireropeTypeID;
            model.WireropeTypeName = entity.WireropeTypeName;
            model.Remark = entity.Remark;
            model.IsOut = entity.IsOut;
            model.NextKeepDate = entity.NextKeepDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override Stock Model2Entity(StockModel model)
        {
            Stock entity = new Stock();

            entity.StockID = model.StockID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.BillID = model.BillID;
            entity.BillDetailID = model.BillDetailID;
            entity.WarehouseID = model.WarehouseID;
            entity.WarehouseName = model.WarehouseName;
            entity.WarehousePositionID = model.WarehousePositionID;
            entity.WarehousePositionName = model.WarehousePositionName;
            entity.Code = model.Code;
            entity.GuiGe = model.GuiGe;
            entity.Diameter = model.Diameter;
            entity.Cnt = model.Cnt;
            entity.Name = model.Name;
            entity.NianJu = model.NianJu;
            entity.MpaID = model.MpaID;
            entity.MpaName = model.MpaName;
            entity.SurfaceStatusID = model.SurfaceStatusID;
            entity.SurfaceStatusName = model.SurfaceStatusName;
            entity.TwistingTypeID = model.TwistingTypeID;
            entity.TwistingTypeName = model.TwistingTypeName;
            entity.LengthNum = model.LengthNum;
            entity.KeepDay = model.KeepDay;
            entity.SupplierID = model.SupplierID;
            entity.SupplierName = model.SupplierName;
            entity.ProducerID = model.ProducerID;
            entity.ProducerName = model.ProducerName;
            entity.ChuChang_Files = model.ChuChang_FilesList.GetFileString();
            entity.YanShou_Files = model.YanShou_FilesList.GetFileString();
            entity.JianCe_Files = model.JianCe_FilesList.GetFileString();
            entity.Attr_Files = model.Attr_FilesList.GetFileString();
            entity.DepartmentID = model.DepartmentID;
            entity.HoisterID = model.HoisterID;
            entity.HoisterName = model.HoisterName;
            entity.HoisterUsageID = model.HoisterUsageID;
            entity.HoisterUsageName = model.HoisterUsageName;
            entity.WireropeTypeID = model.WireropeTypeID;
            entity.WireropeTypeName = model.WireropeTypeName;
            entity.Remark = model.Remark;
            entity.IsOut = model.IsOut;
            entity.NextKeepDate = model.NextKeepDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<Stock> FilterModel2Where(StockFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._StockID.HasValue)
            {
                where = where.And(x => x.StockID == filterModel._StockID.Value);
            }
            if (filterModel._StockIDs.IsNotEmpty() && filterModel._StockIDs.Count > 0)
            {
                where = where.And(x => filterModel._StockIDs.Contains(x.StockID));
            }
            if (filterModel._NotStockIDs.IsNotEmpty() && filterModel._NotStockIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotStockIDs.Contains(x.StockID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //单据
            if (filterModel._BillID.HasValue)
            {
                where = where.And(x => x.BillID == filterModel._BillID.Value);
            }
            if (filterModel._BillIDs.IsNotEmpty() && filterModel._BillIDs.Count > 0)
            {
                where = where.And(x => filterModel._BillIDs.Contains(x.BillID));
            }
            if (filterModel._NotBillIDs.IsNotEmpty() && filterModel._NotBillIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotBillIDs.Contains(x.BillID));
            }

            //单据详细
            if (filterModel._BillDetailID.HasValue)
            {
                where = where.And(x => x.BillDetailID == filterModel._BillDetailID.Value);
            }
            if (filterModel._BillDetailIDs.IsNotEmpty() && filterModel._BillDetailIDs.Count > 0)
            {
                where = where.And(x => filterModel._BillDetailIDs.Contains(x.BillDetailID));
            }
            if (filterModel._NotBillDetailIDs.IsNotEmpty() && filterModel._NotBillDetailIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotBillDetailIDs.Contains(x.BillDetailID));
            }

            //仓库
            if (filterModel._WarehouseID.HasValue)
            {
                where = where.And(x => x.WarehouseID == filterModel._WarehouseID.Value);
            }
            if (filterModel._WarehouseIDs.IsNotEmpty() && filterModel._WarehouseIDs.Count > 0)
            {
                where = where.And(x => filterModel._WarehouseIDs.Contains(x.WarehouseID));
            }
            if (filterModel._NotWarehouseIDs.IsNotEmpty() && filterModel._NotWarehouseIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWarehouseIDs.Contains(x.WarehouseID));
            }

            //仓库名称
            if (!string.IsNullOrEmpty(filterModel._WarehouseName))
            {
                where = where.And(x => x.WarehouseName.Contains(filterModel._WarehouseName));
            }
            if (!string.IsNullOrEmpty(filterModel._WarehouseNameEqual))
            {
                where = where.And(x => x.WarehouseName == filterModel._WarehouseNameEqual);
            }

            //仓库库位
            if (filterModel._WarehousePositionID.HasValue)
            {
                where = where.And(x => x.WarehousePositionID == filterModel._WarehousePositionID.Value);
            }
            if (filterModel._WarehousePositionIDs.IsNotEmpty() && filterModel._WarehousePositionIDs.Count > 0)
            {
                where = where.And(x => filterModel._WarehousePositionIDs.Contains(x.WarehousePositionID));
            }
            if (filterModel._NotWarehousePositionIDs.IsNotEmpty() && filterModel._NotWarehousePositionIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWarehousePositionIDs.Contains(x.WarehousePositionID));
            }

            //仓库库位名称
            if (!string.IsNullOrEmpty(filterModel._WarehousePositionName))
            {
                where = where.And(x => x.WarehousePositionName.Contains(filterModel._WarehousePositionName));
            }
            if (!string.IsNullOrEmpty(filterModel._WarehousePositionNameEqual))
            {
                where = where.And(x => x.WarehousePositionName == filterModel._WarehousePositionNameEqual);
            }

            //编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //钢丝绳名称
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            //抗拉强度
            if (filterModel._MpaID.HasValue)
            {
                where = where.And(x => x.MpaID == filterModel._MpaID.Value);
            }
            if (filterModel._MpaIDs.IsNotEmpty() && filterModel._MpaIDs.Count > 0)
            {
                where = where.And(x => x.MpaID.HasValue && filterModel._MpaIDs.Contains(x.MpaID.Value));
            }
            if (filterModel._NotMpaIDs.IsNotEmpty() && filterModel._NotMpaIDs.Count > 0)
            {
                where = where.And(x => x.MpaID.HasValue && !filterModel._NotMpaIDs.Contains(x.MpaID.Value));
            }

            //抗拉强度名称
            if (!string.IsNullOrEmpty(filterModel._MpaName))
            {
                where = where.And(x => x.MpaName.Contains(filterModel._MpaName));
            }
            if (!string.IsNullOrEmpty(filterModel._MpaNameEqual))
            {
                where = where.And(x => x.MpaName == filterModel._MpaNameEqual);
            }

            //表面状态
            if (filterModel._SurfaceStatusID.HasValue)
            {
                where = where.And(x => x.SurfaceStatusID == filterModel._SurfaceStatusID.Value);
            }
            if (filterModel._SurfaceStatusIDs.IsNotEmpty() && filterModel._SurfaceStatusIDs.Count > 0)
            {
                where = where.And(x => x.SurfaceStatusID.HasValue && filterModel._SurfaceStatusIDs.Contains(x.SurfaceStatusID.Value));
            }
            if (filterModel._NotSurfaceStatusIDs.IsNotEmpty() && filterModel._NotSurfaceStatusIDs.Count > 0)
            {
                where = where.And(x => x.SurfaceStatusID.HasValue && !filterModel._NotSurfaceStatusIDs.Contains(x.SurfaceStatusID.Value));
            }

            //表面状态名称
            if (!string.IsNullOrEmpty(filterModel._SurfaceStatusName))
            {
                where = where.And(x => x.SurfaceStatusName.Contains(filterModel._SurfaceStatusName));
            }
            if (!string.IsNullOrEmpty(filterModel._SurfaceStatusNameEqual))
            {
                where = where.And(x => x.SurfaceStatusName == filterModel._SurfaceStatusNameEqual);
            }

            //捻制类型
            if (filterModel._TwistingTypeID.HasValue)
            {
                where = where.And(x => x.TwistingTypeID == filterModel._TwistingTypeID.Value);
            }
            if (filterModel._TwistingTypeIDs.IsNotEmpty() && filterModel._TwistingTypeIDs.Count > 0)
            {
                where = where.And(x => x.TwistingTypeID.HasValue && filterModel._TwistingTypeIDs.Contains(x.TwistingTypeID.Value));
            }
            if (filterModel._NotTwistingTypeIDs.IsNotEmpty() && filterModel._NotTwistingTypeIDs.Count > 0)
            {
                where = where.And(x => x.TwistingTypeID.HasValue && !filterModel._NotTwistingTypeIDs.Contains(x.TwistingTypeID.Value));
            }

            //捻制类型名称
            if (!string.IsNullOrEmpty(filterModel._TwistingTypeName))
            {
                where = where.And(x => x.TwistingTypeName.Contains(filterModel._TwistingTypeName));
            }
            if (!string.IsNullOrEmpty(filterModel._TwistingTypeNameEqual))
            {
                where = where.And(x => x.TwistingTypeName == filterModel._TwistingTypeNameEqual);
            }

            //供应商
            if (filterModel._SupplierID.HasValue)
            {
                where = where.And(x => x.SupplierID == filterModel._SupplierID.Value);
            }
            if (filterModel._SupplierIDs.IsNotEmpty() && filterModel._SupplierIDs.Count > 0)
            {
                where = where.And(x => x.SupplierID.HasValue && filterModel._SupplierIDs.Contains(x.SupplierID.Value));
            }
            if (filterModel._NotSupplierIDs.IsNotEmpty() && filterModel._NotSupplierIDs.Count > 0)
            {
                where = where.And(x => x.SupplierID.HasValue && !filterModel._NotSupplierIDs.Contains(x.SupplierID.Value));
            }

            //供应商名称
            if (!string.IsNullOrEmpty(filterModel._SupplierName))
            {
                where = where.And(x => x.SupplierName.Contains(filterModel._SupplierName));
            }
            if (!string.IsNullOrEmpty(filterModel._SupplierNameEqual))
            {
                where = where.And(x => x.SupplierName == filterModel._SupplierNameEqual);
            }

            //制造商
            if (filterModel._ProducerID.HasValue)
            {
                where = where.And(x => x.ProducerID == filterModel._ProducerID.Value);
            }
            if (filterModel._ProducerIDs.IsNotEmpty() && filterModel._ProducerIDs.Count > 0)
            {
                where = where.And(x => x.ProducerID.HasValue && filterModel._ProducerIDs.Contains(x.ProducerID.Value));
            }
            if (filterModel._NotProducerIDs.IsNotEmpty() && filterModel._NotProducerIDs.Count > 0)
            {
                where = where.And(x => x.ProducerID.HasValue && !filterModel._NotProducerIDs.Contains(x.ProducerID.Value));
            }

            //制造商名称
            if (!string.IsNullOrEmpty(filterModel._ProducerName))
            {
                where = where.And(x => x.ProducerName.Contains(filterModel._ProducerName));
            }
            if (!string.IsNullOrEmpty(filterModel._ProducerNameEqual))
            {
                where = where.And(x => x.ProducerName == filterModel._ProducerNameEqual);
            }

            //矿山
            if (filterModel._DepartmentID.HasValue)
            {
                where = where.And(x => x.DepartmentID == filterModel._DepartmentID.Value);
            }
            if (filterModel._DepartmentIDs.IsNotEmpty() && filterModel._DepartmentIDs.Count > 0)
            {
                where = where.And(x => x.DepartmentID.HasValue && filterModel._DepartmentIDs.Contains(x.DepartmentID.Value));
            }
            if (filterModel._NotDepartmentIDs.IsNotEmpty() && filterModel._NotDepartmentIDs.Count > 0)
            {
                where = where.And(x => x.DepartmentID.HasValue && !filterModel._NotDepartmentIDs.Contains(x.DepartmentID.Value));
            }

            //提升机类型
            if (filterModel._HoisterID.HasValue)
            {
                where = where.And(x => x.HoisterID == filterModel._HoisterID.Value);
            }
            if (filterModel._HoisterIDs.IsNotEmpty() && filterModel._HoisterIDs.Count > 0)
            {
                where = where.And(x => x.HoisterID.HasValue && filterModel._HoisterIDs.Contains(x.HoisterID.Value));
            }
            if (filterModel._NotHoisterIDs.IsNotEmpty() && filterModel._NotHoisterIDs.Count > 0)
            {
                where = where.And(x => x.HoisterID.HasValue && !filterModel._NotHoisterIDs.Contains(x.HoisterID.Value));
            }

            //提升机类型名称
            if (!string.IsNullOrEmpty(filterModel._HoisterName))
            {
                where = where.And(x => x.HoisterName.Contains(filterModel._HoisterName));
            }
            if (!string.IsNullOrEmpty(filterModel._HoisterNameEqual))
            {
                where = where.And(x => x.HoisterName == filterModel._HoisterNameEqual);
            }

            //提升机用途
            if (filterModel._HoisterUsageID.HasValue)
            {
                where = where.And(x => x.HoisterUsageID == filterModel._HoisterUsageID.Value);
            }
            if (filterModel._HoisterUsageIDs.IsNotEmpty() && filterModel._HoisterUsageIDs.Count > 0)
            {
                where = where.And(x => x.HoisterUsageID.HasValue && filterModel._HoisterUsageIDs.Contains(x.HoisterUsageID.Value));
            }
            if (filterModel._NotHoisterUsageIDs.IsNotEmpty() && filterModel._NotHoisterUsageIDs.Count > 0)
            {
                where = where.And(x => x.HoisterUsageID.HasValue && !filterModel._NotHoisterUsageIDs.Contains(x.HoisterUsageID.Value));
            }

            //提升机用途名称
            if (!string.IsNullOrEmpty(filterModel._HoisterUsageName))
            {
                where = where.And(x => x.HoisterUsageName.Contains(filterModel._HoisterUsageName));
            }
            if (!string.IsNullOrEmpty(filterModel._HoisterUsageNameEqual))
            {
                where = where.And(x => x.HoisterUsageName == filterModel._HoisterUsageNameEqual);
            }

            //钢丝绳类型
            if (filterModel._WireropeTypeID.HasValue)
            {
                where = where.And(x => x.WireropeTypeID == filterModel._WireropeTypeID.Value);
            }
            if (filterModel._WireropeTypeIDs.IsNotEmpty() && filterModel._WireropeTypeIDs.Count > 0)
            {
                where = where.And(x => x.WireropeTypeID.HasValue && filterModel._WireropeTypeIDs.Contains(x.WireropeTypeID.Value));
            }
            if (filterModel._NotWireropeTypeIDs.IsNotEmpty() && filterModel._NotWireropeTypeIDs.Count > 0)
            {
                where = where.And(x => x.WireropeTypeID.HasValue && !filterModel._NotWireropeTypeIDs.Contains(x.WireropeTypeID.Value));
            }

            //钢丝绳类型名称
            if (!string.IsNullOrEmpty(filterModel._WireropeTypeName))
            {
                where = where.And(x => x.WireropeTypeName.Contains(filterModel._WireropeTypeName));
            }
            if (!string.IsNullOrEmpty(filterModel._WireropeTypeNameEqual))
            {
                where = where.And(x => x.WireropeTypeName == filterModel._WireropeTypeNameEqual);
            }

            //是否出库
            if (filterModel._IsOut.HasValue)
            {
                where = where.And(x => x.IsOut == filterModel._IsOut.Value);
            }
            if (filterModel._IsOuts.IsNotEmpty() && filterModel._IsOuts.Count > 0)
            {
                where = where.And(x => filterModel._IsOuts.Contains(x.IsOut));
            }
            
            //下次维保日期
            if (filterModel._NextKeepDate.HasValue)
            {
                where = where.And(x => x.NextKeepDate == filterModel._NextKeepDate.Value);
            }
            if (filterModel._NextKeepDate_Begin.HasValue)
            {
                where = where.And(x => x.NextKeepDate >= filterModel._NextKeepDate_Begin.Value);
            }
            if (filterModel._NextKeepDate_End.HasValue)
            {
                where = where.And(x => x.NextKeepDate < filterModel._NextKeepDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

